package com.example.controller;


import com.example.Pojo.Result;
import com.example.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

//文件上传
@RestController
@Slf4j
public class UploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    //上传图片
    @PostMapping("/upload")
    //这里需要在参数里创建一个MultipartFile的对象,变量名就是image,来获得上传之后的照片的相关信息
    public Result UploadImage(MultipartFile image) throws IOException {
        String url = aliOSSUtils.upload(image);
        log.info("文件上传成功,文件访问的url:" + url);
        return Result.success(url);
    }
}
